package com.dynamixsoftware.printershare;

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.ImageButton;

public class MyImageButton extends ImageButton {

	public MyImageButton(Context var1) {
		super(var1);
	}

	public MyImageButton(Context var1, AttributeSet var2) {
		super(var1, var2);
	}

	public MyImageButton(Context var1, AttributeSet var2, int var3) {
		super(var1, var2, var3);
	}

	public void onDraw(Canvas var1) {
		super.onDraw(var1);
		Object var2 = this.getTag();
		if (var2 != null && var2 instanceof String) {
			String var3 = (String) var2;
			float var4 = Resources.getSystem().getDisplayMetrics().density;
			Rect var5 = var1.getClipBounds();
			Paint var6 = new Paint();
			var6.setStyle(Style.FILL);
			var6.setColor(-1);
			int var7 = Math.round((float) var5.height() / var4 / 5.0F);

			for (int var8 = var7; var8 > 8; --var8) {
				var6.setTextSize(var4 * (float) var8);
				Rect var10 = new Rect();
				var6.getTextBounds(var3, 0, var3.length(), var10);
				if ((float) var10.width() < (float) var5.width() - 10.0F * var4) {
					break;
				}
			}

			var6.setAntiAlias(true);
			var6.setTextAlign(Align.CENTER);
			short var9;
			if (this.isEnabled()) {
				var9 = 255;
			} else {
				var9 = 128;
			}

			var6.setAlpha(var9);
			var1.drawText(var3, (float) (var5.width() / 2), (float) var5.height() - var4 * (float) (10 + var7 / 4),
					var6);
		}
	}

	public void setEnabled(boolean var1) {
		super.setEnabled(var1);
		if (!var1) {
			this.setAlpha(128);
		} else {
			this.setAlpha(255);
		}

		this.invalidate();
	}
}
